﻿using System;
using System.Collections.Generic;
using System.Drawing;

namespace ChessTest.Chess.Items
{
    [Serializable]
    class RooksItem : Chessman
    {
        public override string DisplayName => "车";

        public override bool CanOriginMove(Chessboard chessboard,int selectX, int selectY)
        {
            if (!base.CanOriginMove(chessboard,selectX, selectY)) return false;

            //先确保是走直线的
            if (selectY != PositionY && selectX != PositionX)
                return false;


            for (int x = selectX+1; x < PositionX; x++)
                if (chessboard.GetChessman(x, PositionY) != null)
                    return false;

            for (int x = PositionX + 1; x < selectX; x++)
                if (chessboard.GetChessman(x, PositionY) != null)
                    return false;

            for (int y = selectY+1; y < PositionY; y++)
                if (chessboard.GetChessman(PositionX, y) != null)
                    return false;
            for (int y = PositionY + 1; y < selectY; y++)
                if (chessboard.GetChessman(PositionX, y) != null)
                    return false;

            return true;
        }
        public override List<Point> GetOriginCanMoveList(Chessboard chessboard)
        {
            List<Point> list = new List<Point>();

            for(int x=PositionX+1;x< chessboard.MaxX&& CanOriginMove(chessboard,x, PositionY); x++)
                    list.Add(new Point(x, PositionY));

            for (int x = PositionX - 1; x >=0 && CanOriginMove(chessboard,x, PositionY); x--)
                list.Add(new Point(x, PositionY));

            for (int y = PositionY + 1; y < chessboard.MaxY && CanOriginMove(chessboard,PositionX, y); y++)
                list.Add(new Point(PositionX, y));

            for (int y = PositionY - 1; y >=0 && CanOriginMove(chessboard,PositionX, y); y--)
                list.Add(new Point(PositionX, y));

            return list;
        }

        public override int Score => 10;

    }
}
